package cn.wolfcode.web.controller;

import cn.wolfcode.domain.Permission;
import cn.wolfcode.qo.JsonResult;
import cn.wolfcode.qo.PermissionQuery;
import cn.wolfcode.service.IPermissionService;
import cn.wolfcode.util.RequiredPermission;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("permission")
public class PermissionController {

    @Autowired
    private IPermissionService permissionService;

    @RequestMapping("list")
    @RequiredPermission(name = "权限列表",expression ="permission:list")
    public String list(Model model, PermissionQuery qo){
        PageInfo<Permission> pageInfo = permissionService.query(qo);
        model.addAttribute("pageInfo",pageInfo);
        return "/permission/list";
    }

    @RequestMapping("/delete")
    @RequiredPermission(name = "权限删除",expression ="permission:delete")
    @ResponseBody
    public JsonResult delete(Long id){
        if (id != null){
            permissionService.delete(id);
        }
        return new JsonResult();
    }

    @RequestMapping("/reload")
    @RequiredPermission(name = "权限加载",expression ="permission:reload")
    @ResponseBody
    public JsonResult reload(){
        permissionService.reload();
        return new JsonResult();
    }
}
